Using wildcards in imports may look cleaner as it reduces the number of lines in the import section and simplifies the code.
On the other hand,
it makes the code harder to maintain:
- It reduces code readability as developers will have a hard time knowing where names come from.
- It could lead to conflicts between names defined locally and the ones imported.
- It could later raise conflicts on dependency upgrade or Java version migration, as a wildcard import that works today might be broken tomorrow.
That is why it is better to import only the specific classes or modules you need.
Exceptions
Static imports are ignored by this rule. For example:
import static java.lang.Math.*;
will not raise an issue;